package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TDaoshi;
import com.ruoyi.system.service.ITDaoshiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的导师Controller
 *
 * @author ruoyi
 * @date 2024-05-30
 */
@RestController
@RequestMapping("/system/daoshi")
public class TDaoshiController extends BaseController
{
    @Autowired
    private ITDaoshiService tDaoshiService;


    /**
     * 查询我的导师列表(前台不分页条件查询)
     */
    @GetMapping("/app/list")
    public AjaxResult applist(TDaoshi tDaoshi)
    {
        //参数后台取，防止注入
        tDaoshi.setUserId(getUserInfoUserId());
        logger.info("查到查询我的导师的请求");
        List<TDaoshi> list = tDaoshiService.selectTDaoshiList(tDaoshi);
        logger.info("结束查询我的导师的请求");
        return AjaxResult.success(list);
    }


    /**
     * 查询我的导师列表
     */
    @PreAuthorize("@ss.hasPermi('system:daoshi:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDaoshi tDaoshi)
    {
        startPage();
        List<TDaoshi> list = tDaoshiService.selectTDaoshiList(tDaoshi);
        return getDataTable(list);
    }

    /**
     * 导出我的导师列表
     */
    @PreAuthorize("@ss.hasPermi('system:daoshi:export')")
    @Log(title = "我的导师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDaoshi tDaoshi)
    {
        List<TDaoshi> list = tDaoshiService.selectTDaoshiList(tDaoshi);
        ExcelUtil<TDaoshi> util = new ExcelUtil<TDaoshi>(TDaoshi.class);
        util.exportExcel(response, list, "我的导师数据");
    }

    /**
     * 获取我的导师详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:daoshi:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tDaoshiService.selectTDaoshiById(id));
    }

    /**
     * 新增我的导师
     */
    @PreAuthorize("@ss.hasPermi('system:daoshi:add')")
    @Log(title = "我的导师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDaoshi tDaoshi)
    {
        return toAjax(tDaoshiService.insertTDaoshi(tDaoshi));
    }

    /**
     * 修改我的导师
     */
    @PreAuthorize("@ss.hasPermi('system:daoshi:edit')")
    @Log(title = "我的导师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDaoshi tDaoshi)
    {
        return toAjax(tDaoshiService.updateTDaoshi(tDaoshi));
    }

    /**
     * 删除我的导师
     */
    @PreAuthorize("@ss.hasPermi('system:daoshi:remove')")
    @Log(title = "我的导师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDaoshiService.deleteTDaoshiByIds(ids));
    }
}
